package com.javademo.maptest;

import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

@Slf4j
public class HashMapTest {
    public static void main(String[] args) {
        Map<Integer, String> mapTest = new HashMap<>();
        mapPutTest(mapTest);
        log.info("mapTest: {}", mapTest);
        mapTest.putIfAbsent(2, "c");
        mapTest.putIfAbsent(5, "e");
        log.info("mapTest1: {}", mapTest);
        log.info("mapTest2: {}", mapTest.getOrDefault(6, "未找到"));
        log.info("mapTest3: {}", mapTest.containsValue("5"));
        mapTest.replace(2, "b", "d");
        log.info("mapTest4: {}", mapTest);
        log.info("mapTest5: {}", mapTest.keySet());
        log.info("mapTest6: {}", mapTest.values());
        log.info("mapTest7: {}", mapTest.entrySet());
    }

    private static void mapPutTest(Map<Integer, String> mapTest) {
        mapTest.put(1, "a");
        mapTest.put(2, "b");
        mapTest.put(3, "c");
        mapTest.put(4, "d");
    }
}
